
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-03-14
 * Time: 16:18
 */
import java.util.Comparator;
import java.util.PriorityQueue;

////扑克牌
//class Card implements Comparable<Card>{
//    public int rank; // 数值
//    public String suit; // 花色
//    public Card(int rank, String suit) {
//        this.rank = rank;
//        this.suit = suit;
//    }
//
//    @Override
//    //使用Comparable接口，需要重写compareTo方法
//    //按照扑克牌的数值进行比较
//    public int compareTo(Card o) {
//        return o.rank - this.rank ;
//    }
//
//    @Override
//    //重写 toString 方法
//    public String toString() {
//        return "Card{" +
//                "rank=" + rank +
//                ", suit='" + suit + '\'' +
//                '}';
//    }
//}

//扑克牌
class Card {
    public int rank; // 数值
    public String suit; // 花色
    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    //重写 toString 方法
    public String toString() {
        return "Card{" +
                "rank=" + rank +
                ", suit='" + suit + '\'' +
                '}';
    }
}

//class RankComparator implements Comparator<Card> {
//
//    @Override
//    public int compare(Card o1, Card o2) {
//        return o1.rank - o2.rank;
//    }
//}

public class Test {
    public static void main(String[] args) {
        Card card1 = new Card(1, "♠");
        Card card2 = new Card(2, "♠");
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>((x,y) -> {return y.rank-x.rank;} );
        priorityQueue.offer(card1);
        priorityQueue.offer(card2);
        System.out.println(priorityQueue);
    }

    public static void main3(String[] args) {
        Card card1 = new Card(1, "♠");
        Card card2 = new Card(2, "♠");
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.rank - o1.rank;
            }
        });
        priorityQueue.offer(card1);
        priorityQueue.offer(card2);
        System.out.println(priorityQueue);
    }

    public static void main2(String[] args) {
        Card card1 = new Card(1, "♠");
        Card card2 = new Card(2, "♠");
  //      RankComparator rankComparator = new RankComparator();
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.rank - o2.rank;
            }
        });
        priorityQueue.offer(card1);
        priorityQueue.offer(card2);
        System.out.println(priorityQueue);
    }

    public static void main1(String[] args) {
        Card card1 = new Card(1, "♠");
        Card card2 = new Card(2, "♠");
   //     RankComparator rankComparator = new RankComparator();
     //    int ret = rankComparator.compare(card1,card2);
        System.out.println();
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(new Card(2, "♠"));
        priorityQueue.offer(new Card(1, "♠"));
        System.out.println(priorityQueue);
    }
}
